package se.jocke.nbrs.model;

import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

/**
 *
 * @author jocke
 */
@XmlAccessorType(XmlAccessType.FIELD)
public final class RestService {

    @XmlElement(name = "name")
    private String name;

    @XmlElement(name = "path")
    private String path;

    @XmlElementWrapper(name = "hosts")
    @XmlElement(name = "host")
    private List<String> hosts;

    @XmlElement(name = "content-type")
    private String contentType;

    @XmlElement(name = "accept")
    private String accept;

    @XmlElement(name = "body")
    private String body;

    @XmlElement(name = "user-name")
    private String userName;

    @XmlElement(name = "password")
    private String password;

    @XmlElementWrapper(name = "parameters")
    private Map<String, String> parameters;

    @XmlElementWrapper(name = "headers")
    private Map<String, String> headers;

    private String method;

    public RestService() {
        this.hosts = new ArrayList<String>();
        this.parameters = new HashMap<String, String>();
        this.headers = new HashMap<String, String>();
    }

    public RestService(String name) {
        this.name = name;
        this.hosts = new ArrayList<String>();
        this.parameters = new HashMap<String, String>();
        this.headers = new HashMap<String, String>();

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public List<String> getHosts() {
        return hosts;
    }

    public void setHosts(List<String> hosts) {
        this.hosts = Lists.newArrayList(hosts);
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public Map<String, String> getParameters() {
        return parameters;
    }

    public void setParameters(Map<String, String> parameters) {
        this.parameters = new HashMap<String, String>(parameters);
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = new HashMap<String, String>(headers);
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getAccept() {
        return accept;
    }

    public void setAccept(String accept) {
        this.accept = accept;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 41 * hash + (this.path != null ? this.path.hashCode() : 0);
        hash = 41 * hash + (this.hosts != null ? this.hosts.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RestService other = (RestService) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.path == null) ? (other.path != null) : !this.path.equals(other.path)) {
            return false;
        }
        if (this.hosts != other.hosts && (this.hosts == null || !this.hosts.equals(other.hosts))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "RestService{" + "name=" + name + ", path=" + path + ", hosts=" + hosts + '}';
    }

}
